<template>
	<view class="content">
		<text class="status" v-if="status==0">未核销</text>
		<text class="status" v-else-if="status==1">已核销</text>
		<text class="status" v-else-if="status==3">核销成功</text>
		<text class="status" v-else-if="status==4">核销失败</text>
		<text class="status" v-else-if="status==5">未查询到数据</text>
		<view class="infoBox" v-if="status!=5">
			<view class="titleBox">
				订单详情
			</view>
			<view class="item item1">
				<text class="left">订单编号:</text>
				<text class="right">{{info.sn}}</text>
			</view>
			<view class="item">
				<text class="left">创建时间:</text>
				<text class="right">{{info.create_time}}</text>
			</view>
			<view class="item">
				<text class="left">付款时间:</text>
				<text class="right">{{info.pay_time}}</text>
			</view>
		</view>
		<view class="sure" v-if="status==0" @click="sure()">
			确认核销
		</view>
		<view class="again" v-else-if="status==4" @click="sure()">
			再次核销
		</view>
	</view>
</template>

<script>
	export default {
		data() {
			return {
				status: 1, //核销状态
				id: '',
				info: '',
			}
		},
		onShow(options) {
			let pagearr = getCurrentPages();
			let currentPage = pagearr[pagearr.length - 1];
			this.id = currentPage.options.id;
			if (this.id != 0) {
				this.$request.get(`shopapi/order/detail?id=${this.id}`).then(res => {
					console.log(res.data.data == null)
					if (res.data.data == null) { //未查询到数据
						this.status =5;
					} else {
						this.info = res.data.data;
						this.status = this.info.verification_status;
						this.text = this.info.id;
					}
				})
			}
		},
		onLoad() {
		},
		methods: {
			sure() {
				this.$request.get(`shopapi/order/activity_goods?order_id=${this.id}`).then(res => {
					console.log(res.data.data);
					if (res.data.code == 1) { //核销成功
						this.status = 3;
						this.$toast({
							title:'核销成功'
						})
					} else {
						this.status = 4;
						this.$toast({
							title:'核销失败'
						})
					}
				})
			}
		}
	}
</script>

<style scoped lang="scss">
	.again,
	.sure {
		width:250rpx;
		height: 90rpx;
		line-height: 90rpx;
		background-color: #f08229;
		margin-left: 250rpx;
		margin-top: 95rpx;
		text-align: center;
		font-size: 28rpx;
		color: #fff;
		font-family: 'am';
		border-radius: 45rpx;
	}

	.infoBox {
		width: 690rpx;
		height: 400rpx;
		margin-left: 30rpx;
		margin-top: 100rpx;
		border-radius: 20rpx;
		background-color: #fff;
		background-size: 100% 100%;

		.item {
			width: 590rpx;
			margin-left: 50rpx;
			font-size: 24rpx;
			margin-top: 25rpx;
			display: flex;
			justify-content: space-between;
			font-weight: 700;
		}

		.item1 {
			margin-top: 30rpx;
		}

		.titleBox {
			width: 690rpx;
			height: 80rpx;
			font-size: 26rpx;
			line-height: 80rpx;
			text-align: center;
			// color: #A18055;
		}
	}

	.status {
		display: block;
		width: 100%;
		text-align: center;
		color: #000;
		font-size: 30rpx;
		margin-top: 150rpx;
		font-family: 'am';
	}

	.logo {
		width: 117rpx;
		height: 117rpx;
		margin-left: 317rpx;
		margin-top: 122rpx;
	}

	.content {
		position: fixed;
		width: 100%;
		height: 100vh;
		overflow-y: scroll;
	}

	page {
		width: 100%;
		height: 100vh;
		overflow-y: scroll;
	}
</style>